<?php
@include_once("commonFunctions.php");
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="CSS/formStyle.css" />
        <script type="text/javascript" src="JavaScript/showTickets_history_ajax.js"></script>
        <title>TTS - Viewing Trouble Tickets</title>
    </head>
    <body onload="disable(); ">
        <div id="logo">
		<img src="logo.png" />
   	</div>
    	<div id="menu">
		<a href="index.php" class="menuitem">Login</a>
		<a href="main.php" class="menuitem">View Tickets</a>
		<a href="submitNewTT.php" class="menuitem">Submit New Ticket</a>
		<p id="districtname">South Georgia</p>
    	</div>
	<div id="infobox" class="gradient">
		<div id="infotext">
			<h3>Ticket history</h3>
			<p>This page displays specific information about a trouble tickets history.</p>
		</div>
	</div>
        <div id="header">
            <?php tts_getheader(); ?>
        </div>
        <a href="javascript:history.go(-1)" class="goback">Go Back</a>
        <br/><br/>
        <?php
            $ttid = $_GET['ttid'];
            $tt = new TT($_GET['ttid']);
            $submittedBy = new Dealer($tt->submittedBy);
            // If the current dealer reading this ticket was assigned to solve the ticket, update the status to read
            if ($dealer->dealerCode == $tt->assignedTo && $tt->currentStatus == "Submitted") {
                echo '<center><font color="red">NOTE: This is your first time reading this ticket, which has been assigned to you.<br/>
                    It\'s status has just been changed to "Read"<br/>A text has just been sent to
                    ' . $submittedBy->firstName . ' ' . $submittedBy->lastName . ' notifying them of the change.' . '</font></center>';
                tts_updateStatus('Read', $tt, $dealer->dealerCode, 'Set to Read through platform');
                //$result = tts_SendText($submittedBy->phone, 'TT Status Change', 'Your Ticket# ' . $tt->id . ' has just been read by ' . $dealer->fullName);
                // uncomment for live
                //
                $tt = new TT($ttid);
            }
            echo 'add texting back in';
            echo '<p class="fullwidth">Ticket Summary</p>';
            tts_getTicketHeader();
            tts_getTicketTR($ttid);
            echo '</table>';
            echo '<p class="fullwidth">Ticket Status Change History</p>';
            echo "<table class=\"maintable\">";
            echo "<tr>
        <td class=\"tableheader\">Modified By</td>
        <td class=\"tableheader\">DateTime Modified</td>
        <td class=\"tableheader\">Notes</td>
        <td class=\"tableheader\">Status</td>
        </tr>";
            for ($i = 0; $i < sizeof($tt->statusArr); $i++) {
                echo '<tr>';
                echo '<td>' . $tt->statusArr[$i]->modifiedBy . '</td>';
                echo '<td>' . $tt->statusArr[$i]->dateTimeChange . '</td>';
                echo '<td>' . $tt->statusArr[$i]->notes . '</td>';
                echo '<td>' . $tt->statusArr[$i]->status . '</td>';
                echo '</tr>';
            }
            echo '</table>';
            echo '</br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>';
            if ($dealer->isMA || $dealer->isSuperMA) {
                $_SESSION['ttid'] = $tt->id;
                $_SESSION['nextStatus'] = tts_getNextStatus($tt->currentStatus);
                echo "<form action='updateStatus.php' method='post' >";
                echo '<input type="submit" value="Update The Status To ' . tts_getNextStatus($tt->currentStatus) . '"class="submit"/>';
                echo "</form>";
            }
        ?>
    </body>
</html>
